package cn.wolfcode.mapper;

import cn.wolfcode.domain.User;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName DataMapper
 * Create by Mike
 * Date 2021/8/15 14:03
 */
public class DataMapper {

    //用户集合
    private static Map<String , User> userData = new HashMap<>();

    //角色集合
    private static Map<String, List<String>> roleData = new HashMap<String, List<String>>();

    //权限集合
    private static Map<String, List<String>> permissionData = new HashMap<String, List<String>>();

    static {
        //初始化用户数据
        User u1 = new User("zhangsan", "c73789ac544955a1009e17cec74bf3e0","45cb27");
        userData.put(u1.getUsername(), u1);
        roleData.put(u1.getUsername(), Arrays.asList("seller"));
        permissionData.put(u1.getUsername(), Arrays.asList("customer:list", "customer:save"));
        User u2 = new User("lisi", "d7bde4363e324511aae66e3a38678086","c4eb61");
        userData.put(u2.getUsername(), u2);
        roleData.put(u2.getUsername(), Arrays.asList("seller", "hr"));
        permissionData.put(u1.getUsername(),
                Arrays.asList("customer:list", "customer:save", "user:list", "user:delete"));
    }
    // 提供静态方法，模拟数据库返回数据
    public static User getUserByName(String username){
        return userData.get(username);
    }
    public static List<String> getRoleByName(String username){
        return roleData.get(username);
    }
    public static List<String> getPermissionByName(String username){
        return permissionData.get(username);
    }

}
